package com.spic.business.train.experience.service.impl;

import java.util.List;

import com.spic.business.train.trainInfo.domain.TrainInfo;
import com.spic.business.train.trainInfo.service.ITrainInfoService;
import com.spic.business.train.trainInfo.service.impl.TrainInfoServiceImpl;
import com.spic.business.train.trainUser.domain.TrainUser;
import com.spic.business.train.trainUser.mapper.TrainUserMapper;
import com.spic.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.spic.business.train.experience.mapper.TrainExperienceMapper;
import com.spic.business.train.experience.domain.TrainExperience;
import com.spic.business.train.experience.service.ITrainExperienceService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 心得体会Service业务层处理
 * 
 * @author spic
 * @date 2021-10-15
 */
@Service
public class TrainExperienceServiceImpl implements ITrainExperienceService 
{
    @Autowired
    private TrainExperienceMapper trainExperienceMapper;
    @Autowired
    private TrainUserMapper trainUserMapper;
    @Autowired
    private ITrainInfoService trainInfoService;


    /**
     * 查询心得体会
     * 
     * @param id 心得体会主键
     * @return 心得体会
     */
    @Override
    public TrainExperience selectTrainExperienceById(String id)
    {
        return trainExperienceMapper.selectTrainExperienceById(id);
    }

    /**
     * 查询心得体会列表
     * 
     * @param trainExperience 心得体会
     * @return 心得体会
     */
    @Override
    public List<TrainExperience> selectTrainExperienceList(TrainExperience trainExperience)
    {
        return trainExperienceMapper.selectTrainExperienceList(trainExperience);
    }

    /**
     * 新增心得体会
     * 
     * @param trainExperience 心得体会
     * @return 结果
     */
    @Override
    @Transactional
    public int insertTrainExperience(TrainExperience trainExperience)
    {
       // trainExperience.setCreateTime(DateUtils.getNowDate());
        TrainUser trainUser=new TrainUser();
        trainUser.setId(trainExperience.getTrainUserId());
        trainUser.setTrainState(1);

        trainUser.setJudge("0");
        trainUserMapper.updateTrainUser(trainUser);
        trainInfoService.updateTrainInfoforUserTrainEnd(trainUserMapper.selectTrainUserById(trainExperience.getTrainUserId()).getTrainInfoId());
        return trainExperienceMapper.insertTrainExperience(trainExperience);
    }

    /**
     * 修改心得体会
     * 
     * @param trainExperience 心得体会
     * @return 结果
     */
    @Override
    @Transactional
    public int updateTrainExperience(TrainExperience trainExperience)
    {
        return trainExperienceMapper.updateTrainExperience(trainExperience);
    }

    /**
     * 批量删除心得体会
     * 
     * @param ids 需要删除的心得体会主键
     * @return 结果
     */
    @Override
    public int deleteTrainExperienceByIds(String[] ids)
    {
        return trainExperienceMapper.deleteTrainExperienceByIds(ids);
    }

    /**
     * 删除心得体会信息
     * 
     * @param id 心得体会主键
     * @return 结果
     */
    @Override
    public int deleteTrainExperienceById(String id)
    {
        return trainExperienceMapper.deleteTrainExperienceById(id);
    }
}
